//index.js
//获取应用实例
const app = getApp()

Page({
    data: {
        region: ['河北省', '邢台市', '桥东区'],
        customItem: '全部',
        phone:'',
        name:'',
        addr:'',
        isClick:0
    },
    bindRegionChange: function (e) {
        this.setData({
            region: e.detail.value
        })
    },
    submitInfo:function () {
        var that = this;
        if(that.data.isClick) return;
        that.data.isClick = 1;
        var reg = /^1[3-9][0-9]{9}$/;
        var checkPhone = reg.test(this.data.phone)
        if(!checkPhone){
            wx.showModal({
                title:'提示',
                content:'请检查手机号码格式',
                showCancle:false,
            });
            that.data.isClick = 0;
            return;
        }
        if(!this.data.name || !this.data.phone || !this.data.addr || !this.data.region){
            wx.showModal({
                title:'提示',
                content:'数据不完整，检查后再提交',
                showCancle:false,
            })
            that.data.isClick = 0;
            return;
        }
        var data = {
            getname:that.data.name,
            gettelphone:that.data.phone,
            getaddrmany:that.data.addr,
            getaddr:that.data.region.join(','),
        }
        app.util.request({
            url:app.globalRequestUrl + '/addradd',
            method:'GET',
            data:data,
            success:function (res) {
                if(res && res.msg == 'success'){
                    wx.showToast({
                        title:'提交成功！',
                        icon:'success'
                    });
                    wx.setStorageSync('name',that.data.name)
                    wx.setStorageSync('phone',that.data.phone)
                    wx.setStorageSync('eva',that.data.eva)

                    setTimeout(function () {
                        wx.switchTab({
                            url:'/pages/my/my'
                        })
                    },2000)
                }
            },
            complete:function () {
                setTimeout(function () {
                    that.data.isClick = 0;
                },1000)
            }
        })
    },
    bindInputChangeName:function (e) {
        this.data.name = e.detail.value
    },
    bindInputChangePhone:function (e) {
        this.data.phone = e.detail.value
    },
    bindInputChangeAddr:function (e) {
        this.data.addr = e.detail.value
    },
})
